package com.ckf.springbootinterceptor.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {


    @PostMapping("/doLogin")
    public String login(String userName, String password, HttpSession session) {
        if (userName.equals("admin") && password.equals("123456")) {

            session.setAttribute("admin", userName);
            /*session.setAttribute("no_login","还没登录");*/

            //登录成功返回index 否则返回登录
            return "index";
        }
        return "login";
    }


    @GetMapping("/login")
    public String loginView() {
        return "login";
    }

    @GetMapping("/no_login")
    public String no_login() {
        return "no_login";
    }


    @GetMapping("/orders")
    public String orders() {
        return "orders";
    }


    @GetMapping("/user")
    public String user() {
        return "user";
    }
}
